<div class="col-lg-12">
  <div class="card col-xl-10 offset-xl-1">
    <div class="card-header border-bottom">
      <h4 class="card-title">站点广告</h4>
    </div>
    <div class="card-body">
      @include('common.error')
      @if(count($site->ads))
      @foreach($site->ads as $ad)
      <form class="form mt-5" action="{{ route('ads.store') }}" method="POST" accept-charset="UTF-8">
        <input type="hidden" name="_token" value="{{ csrf_token() }}">
        <input type="hidden" name="site_id" value="{{ $site->id }}">
        <input type="hidden" name="id" value="{{ $ad->id }}">
        <div class="row">
          <div class="form-group col-lg-4 floating-label">
            <label for="videoTitleLink">广告链接</label>
            <input type="text" class="form-control" id="videoTitleLink" name="link[{{$ad->id}}]" value="{{ old('link[$ad->id]', $ad->link) }}">
          </div>
          <div class="form-group col-lg-4 floating-label">
            <label for="videoTitleLink">广告语</label>
            <input type="text" class="form-control" id="videoTitleLink" name="title[{{$ad->id}}]" value="{{ old('title[$ad->id]', $ad->title) }}">
          </div>
          <div class="form-group col-lg-4 floating-label">
            <label for="videoTitleLink">字体颜色</label>
            <input type="text" class="form-control color-picker" id="videoTitleLink" name="color[{{$ad->id}}]" value="{{ old('color[$ad->id]', $ad->color) }}" style="background-color: {{ old('color[$ad->id]', $ad->color) }}; color: #FFF;">
          </div>
        </div>
        <div class="row">
          <div class="form-group col-lg-4 floating-label">
            <label for="videoTitleLink">边框颜色</label>
            <input type="text" class="form-control color-picker" id="videoTitleLink" name="border_color[{{$ad->id}}]" value="{{ old('border_color[$ad->id]', 'rgb(0,0,0)') }}" style="background-color: {{ old('border_color[$ad->id]', $ad->border_color) }}; color: #FFF;">
          </div>
          <div class="form-group col-lg-4 floating-label">
            <label for="videoTitleLink">字体大小</label>
            <input type="text" class="form-control" id="videoTitleLink" name="size[{{$ad->id}}]" value="{{ old('size[$ad->id]', $ad->size) }}">
          </div>
          <div class="form-group col-lg-4 floating-label">
            <label>闪烁效果</label>
            <div class="row">
              <div class="col-sm-2">
                <div class="custom-control custom-radio radio custom-control-inline">
                  <input type="radio" class="custom-control-input" name="flicker[{{$ad->id}}]" id="male" value="1" @if ( old('flicker[$ad->id]', $ad->flicker) ) checked="" @endif>
                  <label class="custom-control-label" for="male">是</label>
                </div>
              </div>
              <div class="col-sm-2">
                <div class="custom-control custom-radio radio custom-control-inline">
                  <input type="radio" class="custom-control-input" name="flicker[{{$ad->id}}]" id="gender" @if ( !old('flicker[$ad->id]', $ad->flicker) ) checked="" @endif value="0">
                  <label class="custom-control-label" for="gender">否</label>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="form-group col-lg-12 text-righ">
            <button type="submit" class="btn btn-common">修改</button>
          </div>
        </div>
      </form>
      @endforeach
      <div class="table-responsive">
        <table class="table table-bordered mb-0">
          <thead>
            <tr>
              <th>广告语</th>
              <th>广告链接</th>
              <th>字体颜色</th>
              <th>边框颜色</th>
              <th>字体大小</th>
              <th>是否闪烁</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
            @foreach($site->ads as $ad)
            <tr>
              <form class="form mt-5" action="{{ route('ads.update', $ad->id) }}" method="POST" accept-charset="UTF-8">
                <input type="hidden" name="_token" value="{{ csrf_token() }}">
                <input type="hidden" name="_method" value="PUT">
                <td>
                  <input type="text" class="form-control" name="title" value="{{ $ad->title }}">
                </td>
                <td>
                  <input type="text" class="form-control" name="link" value="{{ $ad->link }}">
                </td>
                <td>
                  <input type="text" class="form-control color-picker" name="color" value="{{ $ad->color }}" style="color: #fff; background-color: {{ $ad->color }};">
                </td>
                <td>
                  <input type="text" class="form-control color-picker" name="border_color" value="{{ $ad->border_color }}" style="color: #fff;background-color: {{ $ad->border_color }};">
                </td>
                <td>
                  <input type="text" class="form-control" name="size" value="{{ $ad->size }}">
                </td>
                <td>
                  <div class="row">
                    <div class="col-sm-3">
                      <div class="custom-control custom-radio radio custom-control-inline">
                        <input type="radio" class="custom-control-input" name="flicker" id="male{{$ad->id}}" value="1" @if($ad->flicker)checked="checked"@endif>
                        <label class="custom-control-label" for="male{{$ad->id}}">是</label>
                      </div>
                    </div>
                    <div class="col-sm-3">
                      <div class="custom-control custom-radio radio custom-control-inline">
                        <input type="radio" class="custom-control-input" name="flicker" id="gender{{$ad->id}}" @if(!$ad->flicker)checked="checked"@endif value="0">
                        <label class="custom-control-label" for="gender{{$ad->id}}">否</label>
                      </div>
                    </div>
                  </div>
                </td>
                <td>
                  <button type="submit" class="btn btn-sm btn-common">保存</button>
              </form>
              @can('destroy', $ad)
              <form action="{{ route('ads.destroy', $ad->id) }}" method="POST" style="display: inline;" onsubmit="return confirm('Delete? Are you sure?');">
                {{csrf_field()}}
                <input type="hidden" name="_method" value="DELETE">
                <button type="submit" class="btn btn-sm btn-danger">删除</button>
              </form>
              @endcan
              </td>
            </tr>
            @endforeach
          </tbody>
        </table>
      </div>
      @endif
      <form class="form mt-5" action="{{ route('ads.store') }}" method="POST" accept-charset="UTF-8">
        <input type="hidden" name="_token" value="{{ csrf_token() }}">
        <input type="hidden" name="site_id" value="{{ $site->id }}">
        <div class="row">
          <div class="form-group col-lg-4 floating-label">
            <label for="videoTitleLink">广告链接</label>
            <input type="text" class="form-control" id="videoTitleLink" name="link" value="{{ old('link') }}">
          </div>
          <div class="form-group col-lg-4 floating-label">
            <label for="videoTitleLink">广告语</label>
            <input type="text" class="form-control" id="videoTitleLink" name="title" value="{{ old('title') }}">
          </div>
          <div class="form-group col-lg-4 floating-label">
            <label for="videoTitleLink">字体颜色</label>
            <input type="text" class="form-control color-picker" id="videoTitleLink" name="color" value="{{ old('color', 'rgb(255,0,0)') }}" style="background-color: {{ old('color', 'rgb(255,0,0)') }}; color: #FFF;">
          </div>
        </div>
        <div class="row">
          <div class="form-group col-lg-4 floating-label">
            <label for="videoTitleLink">边框颜色</label>
            <input type="text" class="form-control color-picker" id="videoTitleLink" name="border_color" value="{{ old('border_color', 'rgb(0,0,0)') }}" style="background-color: {{ old('border_color', 'rgb(0,0,0)') }}; color: #FFF;">
          </div>
          <div class="form-group col-lg-4 floating-label">
            <label for="videoTitleLink">字体大小</label>
            <input type="text" class="form-control" id="videoTitleLink" name="size" value="{{ old('size', 18) }}">
          </div>
          <div class="form-group col-lg-4 floating-label">
            <label>闪烁效果</label>
            <div class="row">
              <div class="col-sm-2">
                <div class="custom-control custom-radio radio custom-control-inline">
                  <input type="radio" class="custom-control-input" name="flicker" id="male" value="1" @if ( old('flicker') ) checked="" @endif>
                  <label class="custom-control-label" for="male">是</label>
                </div>
              </div>
              <div class="col-sm-2">
                <div class="custom-control custom-radio radio custom-control-inline">
                  <input type="radio" class="custom-control-input" name="flicker" id="gender" @if ( !old('flicker') ) checked="" @endif value="0">
                  <label class="custom-control-label" for="gender">否</label>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="form-group col-lg-12 text-righ">
            <button type="submit" class="btn btn-common">新增一个广告</button>
          </div>
        </div>
      </form>
    </div>
  </div>
</div>
